package univer.oko.table;

import javax.swing.table.DefaultTableModel;
import java.util.Vector;

public class CDTableModel extends DefaultTableModel {
    private boolean isEditable = true;
    private int editableColumn = -1;

    public CDTableModel(Vector data, Vector columnNames) {
        super(data, columnNames);
    }

    //
    public CDTableModel(int col, boolean f) {
        this.setNumRows(1);
        this.setColumnCount(col);
        this.isEditable = f;
    }

    //
    public CDTableModel(int col, int col_edit) {
        this.setNumRows(1);
        this.setColumnCount(col);
        this.editableColumn = col_edit;
    }

    //
    public CDTableModel(int col, int col_edit, boolean isOtherEditable) {
        this.setNumRows(1);
        this.setColumnCount(col);
        this.editableColumn = col_edit;
        this.isEditable = isOtherEditable;
    }

    //
    public boolean isCellEditable(int row, int col) {
        return isEditable || col == editableColumn;
    }

    //
    public void addRow() {
        Object[] data = {};
        super.addRow(data);
    }

    //
    public void removeRow() {
        super.removeRow(getRowCount() - 1);
    }

    //
    public Class getColumnClass(int col) {
        return (col == editableColumn) ? Boolean.class : String.class;
    }
}

